package eecs285.proj4.gui;

//Class: EECS 285
//Project: 
//Due Date: Monday December 6th, 2010

//NOTES: 

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Point;

import eecs285.proj4.gui.MAction.TYPE;
import static eecs.util.Utility.*;

/**
 * A derived class for actions performed on a Markerboard.
 * 
 * @author Easton Thomas
 * @author Stubbed by Hans Marquard
 */
@SuppressWarnings("serial")
public class Rectangle extends MAction
{
  /**
   * Constructs a rectangle.
   * 
   * @param start_
   *          A corner of the rectangle
   * @param end_
   *          The corner opposite start_
   * @author Hans Marquard
   * @author Vidal Borromeo
   */
  public Rectangle(Point start_, Point end_)
  {
    super(TYPE.RECTANGLE);
    start_pt = start_;
    end_pt = end_;
  }

  
  // ---------------------------------------------------------------------------

  /**
   * Include an additional Point in the mouse movement.
   * 
   * @author Hans Marquard
   */
  public void add_point(Point new_point)
  {
	  end_pt = new_point;
  }
  // ---------------------------------------------------------------------------

  /**
   * Implementation of abstract draw method. Draws this type of object.
   * 
   * @param g2
   *          The Graphics object to draw on.
   * @author Easton Thomas
   * @author Stubbed by Hans Marquard
   */
  public void draw(Graphics2D g2)
  {
    g2.setStroke(new BasicStroke(stroke, BasicStroke.CAP_ROUND,
        BasicStroke.JOIN_ROUND)); // set line width of rectangle
    g2.setColor(color);

    // Functionality for all drag and drop combos
    if( end_pt.y > start_pt.y && end_pt.x > start_pt.x )
    {
      g2.drawRect(start_pt.x, start_pt.y, (end_pt.x - start_pt.x),
          (end_pt.y - start_pt.y));
    }

    else if( end_pt.y < start_pt.y && end_pt.x > start_pt.x )
    {
      g2.drawRect(start_pt.x, end_pt.y, (end_pt.x - start_pt.x),
          (start_pt.y - end_pt.y));
    }

    else if( end_pt.y < start_pt.y && end_pt.x < start_pt.x )
    {
      g2.drawRect(end_pt.x, end_pt.y, (start_pt.x - end_pt.x),
          (start_pt.y - end_pt.y));
    }
    else
    {
      g2.drawRect(end_pt.x, start_pt.y, (start_pt.x - end_pt.x),
          (end_pt.y - start_pt.y));
    }
    
  }// draw
  
}// Rectangle
